Class NeuralNetwork

java.lang.Object
edu.uky.ai.ml.nn.NeuralNetwork

public class NeuralNetwork
extends java.lang.Object
A neural network is a computational model, based roughly on biological networks of neurons, which can be trained to perform well on various kinds of classification and non-linear regression tasks. This particular implementation is a feed-forward network with 0 or more hidden layers.
Author:
Stephen G. Ware
  • Field Summary

    Fields 
    Modifier and Type Field Description
    java.lang.Iterable<Edge> edges
    All the weighted directed edges present in the network
    InputLayer input
    The input neurons
    Layer output
    The output neurons
  • Constructor Summary

    Constructors 
    Constructor Description
    NeuralNetwork​(int input, int output, int hiddenLayers, int hiddenNodes, java.util.Random random)
    Constructs a new neural network of a given size.
  • Method Summary

    Modifier and Type Method Description
    java.lang.String classify​(Database database, double[] input)
    Given a database of examples and a set of values for the input neurons, this method calculates the output of the network and returns the class label of the training example whose output is most similar to the network's output.
    double getAccuracy​(Database database)
    Quantifies how will this network performs on a given database of training examples.
    double getError​(Database database)
    Returns the total error of the network for a given training database.
    double[] getOutput()
    Calculates and returns the values of the output neurons given the current state of the network.
    void setInput​(double[] values)
    Sets the input neurons to the given values.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • input

      public final InputLayer input
      The input neurons
    • output

      public final Layer output
      The output neurons
    • edges

      public final java.lang.Iterable<Edge> edges
      All the weighted directed edges present in the network
  • Constructor Details

    • NeuralNetwork

      public NeuralNetwork​(int input, int output, int hiddenLayers, int hiddenNodes, java.util.Random random)
      Constructs a new neural network of a given size.
      Parameters:
      input - the number of input neurons
      output - the number of output neurons
      hiddenLayers - the number of hidden layers
      hiddenNodes - the number of neurons per hidden layer
      random - a random number generator for setting the initial edge weights
  • Method Details

    • setInput

      public void setInput​(double[] values)
      Sets the input neurons to the given values.
      Parameters:
      values - the values
    • getOutput

      public double[] getOutput()
      Calculates and returns the values of the output neurons given the current state of the network.
      Returns:
      the values of all output neurons
    • getError

      public double getError​(Database database)
      Returns the total error of the network for a given training database. The total error is simply the sum of all errors on the training examples.
      Parameters:
      database - the training database
      Returns:
      the total error
    • classify

      public java.lang.String classify​(Database database, double[] input)
      Given a database of examples and a set of values for the input neurons, this method calculates the output of the network and returns the class label of the training example whose output is most similar to the network's output.
      Parameters:
      database - the training database
      input - the values for the input neurons
      Returns:
      the class label of the example most similar to the network output
    • getAccuracy

      public double getAccuracy​(Database database)
      Quantifies how will this network performs on a given database of training examples. Accuracy is simple the number of correctly classified examples divided by the total number of examples.
      Parameters:
      database - the database of examples
      Returns:
      the accuracy